<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
class Class_M_SHOP extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table = "M_SHOP";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey = "id";
	
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "shop_cd";
	 
	 protected $_cols     = array(
	 	"shop_cd"         => array(AOKI_VARTYPE_STR),
		"shop_name"       => array(AOKI_VARTYPE_STR),
		"block_cd"        => array(AOKI_VARTYPE_STR),
	    "block_name"      => array(AOKI_VARTYPE_STR),
		"local_cd"        => array(AOKI_VARTYPE_STR),
		"local_name"      => array(AOKI_VARTYPE_STR),
	    "postcode"        => array(AOKI_VARTYPE_STR),
		"address"         => array(AOKI_VARTYPE_STR),
		"tel"             => array(AOKI_VARTYPE_STR),
		"zone_aja"        => array(AOKI_VARTYPE_INT),
		"area_aja"        => array(AOKI_VARTYPE_INT),
		"lnews1"          => array(AOKI_VARTYPE_STR),
		"lnews2"          => array(AOKI_VARTYPE_STR),
		"lnews3"          => array(AOKI_VARTYPE_STR),
		"lnews4"          => array(AOKI_VARTYPE_STR),
		"lnews5"          => array(AOKI_VARTYPE_STR),
		"stop_date"       => array(AOKI_VARTYPE_DATE),
//		"parent_shop_cd"  => array(AOKI_VARTYPE_STR),
		"year_sale"       => array(AOKI_VARTYPE_INT),
		"memo"            => array(AOKI_VARTYPE_STR),
	 );
	
	 protected $_checks  = array(
		"shop_cd"      => array( "EXIST","NUM" ),
		"shop_name"    => array( "EXIST" ),
		"local_cd"     => array( "EXIST" ),
		"block_cd"     => array( "EXIST" ),
		"postcode"     => array( "EXIST" ,"ZIP" ),
		"address"      => array( "EXIST" ),
		"year_sale"    => array( "NUM" ),
		"tel"          => array( "EXIST" ,"TEL" ),
		"zone_aja"          => array( "EXIST" ,"NUM" ),
		"area_aja"       => array( "EXIST" ,"NUM" ),
		"stop_date"    => array( "YMD" ),
		
	 );
	 
	 //maxlength 
	 protected $_maxlens  = array(
		"shop_name "   =>  100 ,
		"local_name"   =>  50 ,
		"block_name"   =>  100 ,
		"postcode"     =>  8,
		"address"      =>  200,
		"tel"          =>  20,
//		"smx"          =>  1,
		"center"       =>  1,
	 );
	
	 public function search($where ,&$page = NULL ){
	 	$innerjoin = " inner join M_LOGIN as zone on zone.id = a.zone_aja " .
	 	" inner join M_LOGIN as area on area.id = a.area_aja  ";
		$sql = "SELECT a.*,zone.user_name as zone_name,area.user_name as area_name,  (select  user_name FROM M_LOGIN where id  = a.u_user) as m_user_name from {$this->_table}  a ";
		$sqlcnt = "SELECT COUNT(*) AS cnt FROM M_SHOP a ";
		$sql = $sql.$innerjoin ;
		$sqlcnt = $sqlcnt.$innerjoin ;
		return  parent::search($where ,$page ,$sql, $sqlcnt);
	}
	
	 public function searchcsv($where ,&$page = NULL ){	
	 	
		$sql = "SELECT a.*, " .
				"(select  user_name FROM M_LOGIN where id  = a.u_user) as m_user_name from {$this->_table}  a ";
				//" LEFT JOIN M_SHOP  as p  on a.parent_shop_cd = p.shop_cd "
				
		return  parent::search($where ,$page ,$sql);
	}
	
}

?>